package com.party.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.party.domain.Reply;
import com.party.exception.ServiceException;
import com.party.mapper.ReplyMapper;
import com.party.service.ReplyService;
/**
 * 
 * @author Caizhf
 * @date 2017年5月13日下午10:05:49
 * @version v.0.1
 * @email 1115054416@qq.com 
 *
 * <p>Description: </p>
 *
 */
@Service
@Transactional(propagation=Propagation.REQUIRED)
public class ReplyServiceImpl implements ReplyService{
	
	@Autowired
	private ReplyMapper replyMapper;
	
	//查看详情
	@Override
	public Reply getByReplyId(int reply_id){
		Reply r = replyMapper.findById(reply_id);
		if(r==null)
			throw new ServiceException("这条回复已经过期~");
		return r;
	}

	@Override
	public void deleteReply(int reply_id) {
		if(reply_id==0)
			throw new ServiceException("传参错误");
		int state = replyMapper.deleteById(reply_id);
		if(state==0)
			throw new ServiceException("删除失败，没有这条记录");
	}

	//增加的时候注意把id传入对象中
	@Override
	public Reply addReply(Reply reply){
		reply.setReply_time(new Date());
		int state = replyMapper.add(reply);
		if(reply.getRid()==0||state==0)
			throw new ServiceException("回复失败~");
		return reply;
	}
}
